<div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
        <div class="layui-card hxr-layui-card">
            <div class="layui-form hxradmin-card-header">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">供货商用户名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="users" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn" data-type="reload" id="searchs">搜索</button>
                    </div>
                </div>
            </div>
            <div class="layui-card-body">
                <table class="layui-hide" id="list-select-table" lay-filter="list-select-table"></table>

            </div>
        </div>
    </div>
</div>
<div class="form-btn" style="bottom: -20px;">
    <input type="button" value="确认选择" class="layui-btn selectok">
</div>
<script type="text/html" id="sex">
    {{#  if(d.sex === 1){ }}
    男
    {{#  } else if(d.sex === 2) { }}
    女
    {{#  } else if(d.sex === 0) { }}
    保密
    {{#  } }}
</script>
<script>
    //表格数据渲染
    layui.use(['table', 'form'], function() {
        var table = layui.table,
            form = layui.form,
            $ = layui.$;
        layui.admin.initlist(table,'supplier/list', 275, [
            [{
                type: 'radio'
            }, {
                field: 'supplier_id',
                title: 'ID',
                width: 100
            }, {
                field: 'supplier_name',
                title: '供货商用户名',
                minWidth: 150
            }, {
                field: 'real_name',
                title: '姓名',
                minWidth: 100
            }, {
                field: 'sex',
                title: '性别',
                width: 70,
                templet: '#sex'
            },{
                field: 'tel',
                title: '电话',
                width: 150
            },{
                field: 'card_id',
                title: '身份证号码',
                width: 200,
                templet: '#card_id'
            }, {
                field: 'address',
                title: '住址',
                width: 150
            }]
        ],'#list-select-table',380,{obj:layui.admin.device,val1:'supplier_id',val2:'supplier_id'})
        //搜索
        $('#searchs').on('click', function() {
            var val1 = $('input[name="users"]').val()

            //执行重载
            table.reload('list-select-table', {
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    search_text: val1
                }
            });
        });
        $('.selectok').click(function(){
            var checkStatus = table.checkStatus('list-select-table')
                ,checkData = checkStatus.data[0];

            if(!checkData){
                layer.msg('请选择供货商');
            }else{
                console.log(layui.admin.device)
                layui.admin.device.supplier_id=checkData.supplier_id;
                layui.admin.device.supplier_name=checkData.supplier_name;
                layer.close(layui.admin.pups);

            }
        });
    });
</script>
